﻿using System;
using System.IO;

namespace FBGraph.ClientGenerator.CodeGen
{
    public class BodyWriter : IDisposable
    {
        internal BodyWriter(Action<String> callback)
        {
            this.Callback = callback;
            this.InnerWriter = new CodeGenWriter();
        }

        public CodeGenWriter InnerWriter { get; private set; }
        private Action<String> Callback { get; set; }

        public void WriteLine() { this.InnerWriter.WriteLine(); }
        public void WriteLine(String value) { this.InnerWriter.WriteLine(value); }
        public void WriteLine(String format, params Object[] args) { this.InnerWriter.WriteLine(format, args); }
        public void Write(String format, params Object[] args) { this.InnerWriter.Write(format, args); }

        public CodeGenWriter.IndentContainer Indent() { return this.InnerWriter.Indent(); }

        void IDisposable.Dispose()
        {
            this.Callback.Invoke(this.InnerWriter.ToString());
            ((IDisposable)this.InnerWriter).Dispose();
        }
    }
}
